import axios from 'axios'
import Qs from 'qs'
import { Loading } from 'element-ui';

axios.defaults.timeout = 10000
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

export function get(url, params) {
  return new Promise((resolve, reject) => {
    axios.get(url, {params, params}).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err.data)
    })
  })
}

export function post(url, params) {
  return new Promise((resolve, reject) => {
    axios.post(url, Qs.stringify(params)).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err.data)
    })
  })
}

export function del(url, params) {
  return new Promise((resolve, reject) => {
    axios.delete(url, {params, params}).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err.data)
    })
  })
}

